import { PageConfig } from 'next';
import anylogger from 'anylogger';
import '@mmstudio/an000042';
import an48 from '@mmstudio/an000048';
import { tbattendance } from '../../../../atoms/db';

const logger = anylogger('pages/api/zllweapp/attendancequery/s001.api');

export type Result = {
	ok: true;
	week: Pick<ITbattendance, 'week'>[];

} | {
	ok: false;
	message: string;
};

export type Message = {

}

/**
 * pages/api/zllweapp/attendancequery/s001.api
 */
const handler = an48<Result>();

handler.post(async (req, res) => {
	try {

		logger.debug('msg body:', req.body);
		//**查询课程option */
		const student_id = '201942307789';
		const week = await tbattendance().distinct('week').where({
			student_id: student_id
		}).orderBy('week', 'asc');

		res.status(200).json({ ok: true, week, });
	} catch (error) {
		logger.trace(error);
		res.status(200).json({ ok: false, message: (error as Error).message });
	}
});

export const config = {} as PageConfig;
export default handler;
